﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Collections;
using MySql.Data.MySqlClient;
using IPTV.dao;
using IPTV.module;
using System.Data;
using IPTV.DBUtility;


namespace IPTV.service
{
    public class CommonService
    {
        public CommonService()
        {
            
        }

        public void addUser(UserDto user)
        {
            CommonDao cd = new CommonDao();
            int result = cd.getUserById(user.UserId);
            if (result > 0)
            {
                MySqlConnection connection = MySQLHelper.CONNECTION;
                connection.Open();
                MySqlTransaction trn = connection.BeginTransaction();
                try
                {
                    int i = cd.addUserInfo(user, trn);
                    trn.Commit();
                }
                catch (Exception e)
                {
                    trn.Rollback();
                }
                finally
                {
                    connection.Close();
                }
            }
        }

        public void addVisitRecord(VisitRecordDto visitRecord)
        {
            CommonDao cd = new CommonDao();
            MySqlConnection connection = MySQLHelper.CONNECTION;
            connection.Open();
            MySqlTransaction trn = connection.BeginTransaction();
            try
            {
                int i = cd.addVisitRecord(visitRecord, trn);
                trn.Commit();
            }
            catch (Exception e)
            {
                trn.Rollback();
            }
            finally
            {
                connection.Close();
            }


        }
    }

}